class DateTime {
	constructor() {
		this._localStorage = window.localStorage;
		this._sidebarClock = document.querySelector('#user-profile-clock');
		this._sidebarDate = document.querySelector('#user-profile-date');
		this._greeterMessage = document.querySelector('#greeter-message');
		this._greeterClock = document.querySelector('#greeter-clock');
		this._greeterDate = document.querySelector('#greeter-date');
		this._setTime = this._setTime.bind(this);
		this._twentyFourMode = false;
		this._clockUpdater = null;
		this._monthsArr = [
			'一月',
			'二月',
			'三月',
			'四月',
			'五月',
			'六月',
			'七月',
			'八月',
			'九月',
			'十月',
			'十一月',
			'十二月'
		];

		this._daysArr = [
			'星期天',
			'星期一',
			'星期二',
			'星期三',
			'星期四',
			'星期五',
			'星期六'
		];

		this._init();
	}

	_getDayOrdinal(day) {
		return day;
	}

	// Append zero
	_appendZero(k) {
		// Append 0 before time elements if less hour's than 10
		if (k < 10) {
			return '0' + k;
		} else {
			return k;
		}
	}

	_setTime() {
		const date = new Date();
		let hour = date.getHours();
		let min = date.getMinutes();
		let greeterSuffix = null;
		min = this._appendZero(min);

		if (hour >= 3 && hour < 5) {
			// greeterSuffix = '凌晨';
			greeterSuffix = '现在能看到太阳吗';
		} else if (hour >= 5 && hour < 8) {
			// greeterSuffix = '早晨';
			greeterSuffix = '吃早餐了吗';
		} else if (hour >= 8 && hour < 11) {
			// greeterSuffix = '上午';
			greeterSuffix = '该吃早茶了';
		} else if (hour >= 11 && hour < 13) {
			// greeterSuffix = '中午';
			greeterSuffix = '吃午餐了吗';
		} else if (hour >= 13 && hour < 17) {
			// greeterSuffix = '下午';
			greeterSuffix = '该吃下午茶了';
		} else if (hour >= 17 && hour < 19) {
			// greeterSuffix = '傍晚';
			greeterSuffix = '吃晚餐了吗';
		} else if (hour >= 19 && hour < 23) {
			// greeterSuffix = '晚上';
			greeterSuffix = '该吃夜宵了';
		} else {
			// greeterSuffix = '深夜';
			greeterSuffix = '现在能看到月亮吗';
		}

		hour = this._appendZero(hour);
		this._sidebarClock.innerText = `${hour}:${min}`;
		this._greeterClock.innerText = `${hour}:${min}`;
		// this._sidebarDate.innerText = `${this._daysArr[date.getDay()]}, ${this._monthsArr[date.getMonth()]} ` +
			// `${this._appendZero(date.getDate())}, ${date.getFullYear()}`;
		// this._greeterDate.innerText = `${this._getDayOrdinal(this._appendZero(date.getDate()))} of ` +
			// `${this._monthsArr[date.getMonth()]}, ${this._daysArr[date.getDay()]}`;
		// this._sidebarDate.innerText = `${date.getFullYear()}年${this._monthsArr[date.getMonth()]}${this._appendZero(date.getDate())}号${this._daysArr[date.getDay()]}`;
		// this._greeterDate.innerText = `${this._monthsArr[date.getMonth()]}${this._getDayOrdinal(this._appendZero(date.getDate()))}号${this._daysArr[date.getDay()]}`;
		this._sidebarDate.innerText = `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}号${this._daysArr[date.getDay()]}`;
		this._greeterDate.innerText = `${date.getMonth() + 1}月${date.getDate()}号${this._daysArr[date.getDay()]}`;
		this._greeterMessage.innerText = `${greeterSuffix}`;
	}

	_startClock() {
		this._setTime();
		this._clockUpdater = setInterval(this._setTime, 1000);
	}

	_init() {
		this._startClock();
	}
}
